<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>文件上传</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="../static/plugins/layui-v2.2.5/css/layui.css" media="all">
    <script src="../static/plugins/layui-v2.2.5/layui.js"></script>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
</head>
<body>
<button type="button" class="layui-btn" id="addFile">
    <i class="layui-icon">&#xe67c;</i>添加文件
</button>
<button type="button" class="layui-btn" id="b1">
    booting_2
</button>
<button type="button" class="layui-btn" id="b2">
    booting_3
</button>
<div class="layui-progress layui-progress-big" lay-showpercent="true" lay-filter="uploadProgressBar">
    <div class="layui-progress-bar" lay-percent="0%"></div>
</div>
<p id="tip"></p>
<ul id="content"></ul>
</body>
<script>
    layui.use(["layer","form", "upload","jquery","element"], function () {
        // 注意：为了动态显示进度条，必须加载element组件
        var layer = layui.layer, upload = layui.upload, $ = layui.jquery, element = layui.element;

        upload.render({
            accept : "file",
            elem : "#addFile",
            auto : true,   //关闭文件自动上传
            url : "upload",
            progress:function(value){//上传进度回调 value进度值
                element.progress('uploadProgressBar', value+'%')//设置页面进度条
            },
            done : function (res, index, upload) {
                if(res.code != 200){
                    layer.open({
                        icon : 2,
                        skin : "layui-layer-molv",
                        content : res.msg
                    });
                }
            },
            error : function (res) {
            }
        });

    });


    $("#b1").click(function(){
        $("#tip").html("正在统计...");
        $("#content").html("");
        $.post("calc",
            {type:"1"},
            function(data,status){
                populateSavedCounties($("#content"), data.value);
                //alert("数据: \n" + data + "\n状态: " + status);
            });
    });

    $("#b2").click(function(){
        $("#tip").html("正在统计...");
        $("#content").html("");
        $.post("calc",
            {type:"2"},
            function(data,status){
                populateSavedCounties($("#content"), data.value);
            });
    });
    function populateSavedCounties(select, data) {
        var items = [];
        $.each(data, function (id, option) {
            items.push('<li>' + id+":" + option.valueOf() + '</li>');
        });
        select.html(items.join(''));
    }
</script>
</html>
